var echartsTheme = 'macarons';

function barGo1() {
    var myChart = echarts.init(document.getElementById('div_bar1'), echartsTheme);
    option = {
        color: ['#3398DB'],
        tooltip: {
            trigger: 'axis',
            axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            }
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        dataZoom: {
            showDetail: false,
            zoomLock: false,
            height: 16,
            realtime: true,
            start: 0,
            end: 70,
            handleSize: 4
        },
        xAxis: [

            {
                type: 'category',
                axisLabel: {
                    interval: 0,
                    rotate: 45,   //标签倾斜显示
                    formatter: function (val) {
                        var strs = val.split('');
                        var str = '';
                        for (var i = 0, s; s = strs[i++];) {
                            str += s;
                            if (!(i % 8)) {
                                str += '\n';
                            }
                        }
                        return str;
                    }

                },
                data: [],
                axisTick: {
                    alignWithLabel: true
                }
            }
        ],
        yAxis: [
            {
                type: 'value'
            }
        ],
        series: [
            {
                name: '主营业收入',
                type: 'bar',
                barWidth: '40%',
                data: []
            }
        ]
    };
    myChart.setOption(option);
    var lay = layer.load({shade: [0.1]});
    $.ajax({
        url: ctx + "/mge/adx/syfx/zhfx/queryZyywpm",
        data: $("#from_rd").formSerialize(),
        dataType: "json",
        type: 'post',
        success: function (d, s) {
            layer.close(lay);
            if (d.code == '200') {
                var datas = d.data;
                if (datas != null) {
                    //隐藏loading动画
                    myChart.hideLoading();
                    myChart.setOption({
                        xAxis: [{
                            data: datas.xAxisData
                        }],
                        series: [{
                            data: datas.sr
                        }]
                    });
                    $("#v_zyysrpm").html("主营业收入行业排名为<span style='color: red' >" + datas.pm + "</span> (共" + datas.total + "家企业)");
                }

            } else {
                layer.alert(d.message);
            }
        }, error: function (sta) {
            layer.close(lay);
            layer.alert("请求失败，请重试或检查网络！");
        }
    });
}

function barGo2() {
    var myChart = echarts.init(document.getElementById('div_bar2'), echartsTheme);
    var labelRight = {
        normal: {
            position: 'top'
        }
    };
    var option = {
        title: [
            {
                //text: '正负条形图',
                left: 'center',
                top: 20,
                textStyle: {
                    color: 'blue'
                },
            },
            {
                textStyle: {
                    fontSize: 14
                },
                left: 'center',
                top: '88%'
            }
        ],
        tooltip: {
            trigger: 'axis',//坐标轴触发，主要在柱状图，折线图等会使用类目轴的图表中使用。
            axisPointer: { // 坐标轴指示器，坐标轴触发有效
                type: 'shadow' // 默认为直线，可选为：'line' | 'shadow' |'cross'
            }
        },
        legend: {show: false},
        grid: {
            left: '10%',
            right: '10%',
            bottom: '5%',
            containLabel: true
        },
        dataZoom: {
            showDetail: false,
            zoomLock: false,
            height: 16,
            realtime: true,
            start: 0,
            end: 70,
            handleSize: 4
        },
        xAxis: [{
            type: 'category',
            axisTick: { //坐标轴刻度相关设置。
                show: false
            },
            axisLabel: {
                interval: 0,
                rotate: 45,   //标签倾斜显示
                formatter: function (val) {
                    var strs = val.split('');
                    var str = '';
                    for (var i = 0, s; s = strs[i++];) {
                        str += s;
                        if (!(i % 8)) {
                            str += '\n';
                        }
                    }
                    return str;
                }
            },
            data: []
        }],
        yAxis: [{
            type: 'value',
            //name: 'Z值',
            nameLocation: 'center',
            nameGap: 40
        }],
        series: [
            {
                name: '企业资产收益率',
                type: 'bar',
                barWidth: '40%',
                label: { //图形上的文本标签，可用于说明图形的一些数据信息，比如值，名称等
                    normal: { //正常情况
                        show: true, //是否显示标签
                        position: 'inside', //标签的位置。
                        distance: 5, //距离图形元素的距离。当 position 为字符描述值（如 'top'、'insideRight'）时候有效。default: 5
                        rotate: 0 //标签旋转。从 -90 度到 90 度。正值是逆时针。

                    }
                },
                data: []
            }

        ]
    };
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
    var lay = layer.load({shade: [0.1]});
    $.ajax({
        url: ctx + "/mge/adx/syfx/zhfx/queryJzcsypm",
        data: $("#from_rd").formSerialize(),
        dataType: "json",
        type: 'post',
        success: function (d, s) {
            layer.close(lay);
            if (d.code == '200') {
                var datas = d.data;
                if (datas != null) {
                    //隐藏loading动画
                    myChart.hideLoading();
                    myChart.setOption({
                        xAxis: [{
                            data: datas.xAxisData
                        }],
                        series: [{
                            data: datas.sr
                        }]
                    });
                    $("#v_jzcsylpm").html("净资产收益率行业排名第<span style='color: red;'>" + datas.pm + "</span> (共" + datas.total + "家企业)");
                }

            } else {
                layer.alert(d.message);
            }
        }, error: function (sta) {
            layer.close(lay);
            layer.alert("请求失败，请重试或检查网络！");
        }
    });
}

function zyywsrGo() {
    var myChart = echarts.init(document.getElementById('div_bar3'), echartsTheme);
    var option = optionInit();
    myChart.setOption(option);
    var lay = layer.load({shade: [0.1]});
    $.ajax({
        url: ctx + "/mge/adx/syfx/zhfx/queryZyywsr",
        data: $("#from_rd").formSerialize(),
        dataType: "json",
        type: 'post',
        success: function (d, s) {
            layer.close(lay);
            if (d.code == '200') {
                var datas = d.data;
                if (datas.xAxisData.length > 0) {
                    //隐藏loading动画
                    myChart.hideLoading();
                    myChart.setOption({
                        xAxis: [{
                            data: datas.xAxisData
                        }],
                        series: [{
                            data: datas.bq
                        }, {
                            data: datas.tq
                        }]
                    });
                    if (datas.tj) {
                        $("#v_zywsr").html("累计增幅：" + toFixed(cmm.isNUllZro(datas.tj.ljzf), 100) + "%  &nbsp;&nbsp;平均增幅：" + toFixed(cmm.isNUllZro(datas.tj.pjzf), 100) + "%");
                    }
                } else {
                    $("#div_bar3").html(myQygm.tipTbms(myQygm.getMsxx("QYJZ03")));
                    $("#div_bar3").css({"height": 30, "display": "table"});
                }
            } else {
                layer.alert(d.message);
            }
        }, error: function (sta) {
            layer.close(lay);
            layer.alert("请求失败，请重试或检查网络！");
        }
    });

}

function zyywlrlGo() {
    var myChart = echarts.init(document.getElementById('div_bar5'), echartsTheme);
    var option = optionInit();
    myChart.setOption(option);
    var lay = layer.load({shade: [0.1]});
    $.ajax({
        url: ctx + "/mge/adx/syfx/zhfx/queryZyywlrl",
        data: $("#from_rd").formSerialize(),
        dataType: "json",
        type: 'post',
        success: function (d, s) {
            layer.close(lay);
            if (d.code == '200') {
                var datas = d.data;
                if (datas.xAxisData.length > 0) {
                    //隐藏loading动画
                    myChart.hideLoading();
                    myChart.setOption({
                        xAxis: [{
                            data: datas.xAxisData
                        }],
                        series: [{
                            data: datas.bq
                        }, {
                            data: datas.tq
                        }]
                    });
                    if (datas.tj) {
                        $("#v_zyywlrl").html("累计增幅：" + toFixed(cmm.isNUllZro(datas.tj.ljzf), 100) + "% &nbsp;&nbsp; 平均增幅：" + toFixed(cmm.isNUllZro(datas.tj.pjzf), 100) + "%");
                    }
                } else {
                    $("#div_bar5").html(myQygm.tipTbms(myQygm.getMsxx("QYJZ05")));
                    $("#div_bar5").css({"height": 30, "display": "table"});
                }
            } else {
                layer.alert(d.message);
            }
        }, error: function (sta) {
            layer.close(lay);
            layer.alert("请求失败，请重试或检查网络！");
        }
    });

}

function optionInit() {
    var option = {
        title: {},
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            orient: 'horizontal',
            left: 'center',
            bottom: "1%",
            data: ['本期', '同期']
        },
        toolbox: {
            show: false,
            feature: {
                dataView: {show: true, readOnly: false},
                magicType: {show: true, type: ['line', 'bar']},
                restore: {show: true},
                saveAsImage: {show: true}
            }
        },
        calculable: true,
        xAxis: [
            {
                type: 'category',
                axisLabel: {
                    //inside:true,
                    interval: 0
                },
                data: []
            }
        ],
        yAxis: [
            {
                type: 'value'
            }
        ],
        series: [
            {
                name: '本期',
                type: 'bar',
                barWidth: '10%',
                data: [],
                markPoint: {
                    data: [
                        {type: 'max', name: '最大值'},
                        {type: 'min', name: '最小值'}
                    ]
                },
                markLine: {
                    data: [
                        {type: 'average', name: '平均值'}
                    ]
                }
            },
            {
                name: '同期',
                type: 'bar',
                barWidth: '10%',
                data: [],
                markPoint: {
                    data: [
                        {type: 'max', name: '最大值'},
                        {type: 'min', name: '最小值'}
                    ]
                },
                markLine: {
                    data: [
                        {type: 'average', name: '平均值'}
                    ]
                }
            }
        ]
    };
    return option;
}

function barGo3() {
    var myChart4 = echarts.init(document.getElementById('div_bar4'), echartsTheme);
    var myChart6 = echarts.init(document.getElementById('div_bar6'), echartsTheme);
    var lay = layer.load({shade: [0.1]});
    $.ajax({
        url: ctx + "/mge/adx/syfx/zhfx/queryJzcsyl",
        data: $("#from_rd").formSerialize(),
        dataType: "json",
        type: 'post',
        success: function (d, s) {
            layer.close(lay);
            if (d != null && d.code == "200") {
                if (d.data.list.length > 0) {
                    var list = d.data.list;
                    var tj = d.data.tj;
                    var len = [];
                    var bq = [];
                    var tq = [];
                    for (var l in list) {
                        var lt = list[l];
                        len.push(jdstr(lt.jd));
                        bq.push(toFixed(cmm.isNUllZro(lt.jzcsyl), 100));
                        tq.push(toFixed(cmm.isNUllZro(lt.tqjzcsyl), 100));
                    }
                    var option = axisOption(len, bq, tq);
                    myChart4.setOption(option);
                    if (d.data.tj) {
                        $("#v_jzcsyl").html("累计增幅：" + toFixed(cmm.isNUllZro(d.data.tj.ljzf), 100) + "% &nbsp;&nbsp;平均增幅：" + toFixed(cmm.isNUllZro(d.data.tj.pjzf), 100) + "%");
                    }
                } else {
                    $("#div_bar4").html(myQygm.tipTbms(myQygm.getMsxx("QYJZ02")));
                    $("#div_bar4").css({"height": 30, "display": "table"});
                }
            }
        }, error: function (s) {
            layer.close(lay);
        }
    });
    var lay = layer.load({shade: [0.1]});
    $.ajax({
        url: ctx + "/mge/adx/syfx/zhfx/queryJlrzzl",
        data: $("#from_rd").formSerialize(),
        dataType: "json",
        type: 'post',
        success: function (d, s) {
            layer.close(lay);
            if (d != null && d.code == "200") {
                if (d.data.list.length > 0) {
                    var list = d.data.list;
                    var tj = d.data.tj;
                    var len = [];
                    var bq = [];
                    var tq = [];
                    for (var l in list) {
                        var lt = list[l];
                        len.push(jdstr(lt.jd));
                        bq.push(toFixed(cmm.isNUllZro(lt.jlrzzl), 100));
                        tq.push(toFixed(cmm.isNUllZro(lt.tqjlrzzl), 100));
                    }
                    var option = axisOption(len, bq, tq);
                    myChart6.setOption(option);
                    if (d.data.tj) {
                        $("#v_jlrzzl").html("累计增幅：" + toFixed(cmm.isNUllZro(d.data.tj.ljzf), 100) + "%&nbsp;&nbsp; 平均增幅：" + toFixed(cmm.isNUllZro(d.data.tj.pjzf), 100) + "%");
                    }
                } else {
                    $("#div_bar6").html(myQygm.tipTbms(myQygm.getMsxx("QYJZ06")));
                    $("#div_bar6").css({"height": 30, "display": "table"});
                }
            }
        }, error: function (s) {
            layer.close(lay);
        }
    });


}

function jdstr(l) {
    if (l == "1") {
        return "第一季度";
    }
    if (l == "2") {
        return "第二季度";
    }
    if (l == "3") {
        return "第三季度";
    }
    if (l == "4") {
        return "第四季度";
    }
}

function axisOption(len, bq, tq) {
    var option = {
        title: {},
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            orient: 'horizontal',
            left: 'center',
            bottom: "1%",
            data: ['本期', '同期']
        },
        toolbox: {
            show: false,
            feature: {
                dataView: {show: true, readOnly: false},
                magicType: {show: true, type: ['line', 'bar']},
                restore: {show: true},
                saveAsImage: {show: true}
            }
        },
        calculable: true,
        xAxis: [
            {
                type: 'category',
                data: len
            }
        ],
        yAxis: [
            {
                type: 'value'
            }
        ],
        series: [
            {
                name: '本期',
                type: 'bar',
                data: bq,
                barWidth: "10%",
                markPoint: {
                    data: [
                        {type: 'max', name: '最大值'},
                        {type: 'min', name: '最小值'}
                    ]
                },
                markLine: {
                    data: [
                        {type: 'average', name: '平均值'}
                    ]
                }
            },
            {
                name: '同期',
                type: 'bar',
                barWidth: "10%",
                data: tq,
                markPoint: {
                    data: [
                        {name: '年最高', value: 182.2, xAxis: 7, yAxis: 183},
                        {name: '年最低', value: 2.3, xAxis: 11, yAxis: 3}
                    ]
                },
                markLine: {
                    data: [
                        {type: 'average', name: '平均值'}
                    ]
                }
            }
        ]
    };
    return option;
}